home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / wv2 / textconverter.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-08-07  |  3.3 KB  |  133 lines

  1. /* This file is part of the wvWare 2 project
  2.    Copyright (C) 2001-2003 Werner Trobin <trobin@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16.    Boston, MA 02111-1307, USA.
  17. */
  18.  
  19. #ifndef TEXTCONVERTER_H
  20. #define TEXTCONVERTER_H
  21.  
  22. #include "global.h"
  23. #include <string>
  24.  
  25. namespace wvWare
  26. {
  27.  
  28. class UString;
  29.  
  30. /**
  31.  * A small tool class to provide a convenient interface to iconv.
  32.  */
  33. class TextConverter
  34. {
  35. public:
  36.     /**
  37.      * Construct a TextConverter
  38.      */
  39.     TextConverter( const std::string& toCode, const std::string& fromCode );
  40.     /**
  41.      * Constructs a TextConverter which converts to UCS-2
  42.      */
  43.     TextConverter( const std::string& fromCode );
  44.     /**
  45.      * Constructs a TextConverter which converts from the proper
  46.      * codepage for the given lid to UCS-2. This is probably what
  47.      * you want to use.
  48.      */
  49.     TextConverter( U16 lid );
  50.  
  51.     /**
  52.      * Properly cleans up
  53.      */
  54.     ~TextConverter();
  55.  
  56.     /**
  57.      * Is the converter okay?
  58.      */
  59.     bool isOk() const;
  60.  
  61.     /**
  62.      * Change the converter to convert to that code
  63.      */
  64.     void setToCode( const std::string& toCode );
  65.     std::string toCode() const;
  66.  
  67.     /**
  68.      * Change the converter to convert from that code
  69.      */
  70.     void setFromCode( const std::string& fromCode );
  71.     std::string fromCode() const;
  72.  
  73.     /**
  74.      * Convert the string to the specified encoding (most likely UCS-2).
  75.      * Note: No other conversions are really supported, as we don't
  76.      * need them anyway.
  77.      */
  78.     UString convert( const std::string& input ) const;
  79.  
  80.     /**
  81.      * Convert the string to the specified encoding (most likely UCS-2).
  82.      * Note: No other conversions are really supported, as we don't
  83.      * need them anyway.
  84.      */
  85.     UString convert( const char* input, unsigned int length ) const;
  86.  
  87.     /**
  88.      * "stolen" from wvWare, guesses a lid for some locales.
  89.      */
  90.     static U16 locale2LID( U8 nLocale );
  91.  
  92.     /**
  93.      * "stolen" from the wvWare, guesses a lang for some lids.
  94.      */
  95.     static const char* LID2lang( U16 lid );
  96.  
  97.     /**
  98.      * returns the appropriate codepage for the given lid.
  99.      */
  100.     static const char* LID2Codepage( U16 lid );
  101.  
  102. private:
  103.     /**
  104.      * Don't copy us
  105.      */
  106.     TextConverter( const TextConverter& rhs );
  107.     /**
  108.      * Don't assign us
  109.      */
  110.     TextConverter& operator=( const TextConverter& rhs );
  111.  
  112.     /**
  113.      * Closes the old converter
  114.      */
  115.     void close();
  116.  
  117.     /**
  118.      * Opens a converter
  119.      */
  120.     void open();
  121.  
  122.     static U16 fixLID( U16 nLocale );
  123.  
  124.     // We need this private impl. to hide the iconv_t in the source file. The
  125.     // reason is that we can't #include <config.h> in the header file!
  126.     class Private;
  127.     Private* d;
  128. };
  129.  
  130. } // namespace wvWare
  131.  
  132. #endif // TEXTCONVERTER_H
  133.